package com.wrial.offer;
/*
 * @Author  Wrial
 * @Date Created in 16:53 2020/4/2
 * @Description 第一个只出现一次的字符
 */

import java.util.HashMap;
import java.util.Map;

public class FaceTest_20 {
    public char firstUniqChar(String s) {
        Map<Character,Boolean> map = new HashMap();
        char ans = ' ';
        char[] chars = s.toCharArray();
        for(int i=0;i<chars.length;i++){
            if (map.containsKey(chars[i])){
                map.put(chars[i], false);
            }else{
                map.put(chars[i],true);
            }
        }
        // 找到第一个就返回
        for (int i = 0; i < s.length(); i++) {
            if (map.get(chars[i])) return chars[i];
        }
        return ans;
    }
}
